package com.sdry.service.impl.hpf;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.sdry.mapper.hpf.WarningMapper;
import com.sdry.model.hpf.Warning;
import com.sdry.service.hpf.WarningService;

/**
 * @ClassName: WarningServiceImpl 
 * @Description:预警管理Service实现
 * @Author hpf
 * @Date 2018年9月25日 上午9:18:05 
 * @version 1.0
 */
@Service
public class WarningServiceImpl implements WarningService {

	@Resource
	private WarningMapper warningMapper;
	
	/**
	 * 查询总数
	 * @param beat
	 * @return
	 */
	public Integer countWarning(Warning warning) {
		return warningMapper.countWarning(warning);
	}

	/**
	 * 分页查询
	 * @param map
	 * @return
	 */
	public List<Warning> listPageWarning(Map<String, Object> map) {
		return warningMapper.listPageWarning(map);
	}

	/**
	 * 新增预警管理
	 * @param warning
	 * @return
	 */
	public Integer insertWarning(Warning warning) {
		Date date = new Date();
		warning.setWtime(date);
		return warningMapper.insertWarning(warning);
	}

	/**
	 * 修改预警管理
	 * @param warning
	 * @return
	 */
	public Integer updateWarning(Warning warning) {
		// TODO Auto-generated method stub
		return warningMapper.updateWarning(warning);
	}

	/**
	 * 删除预警管理
	 * @param wid
	 * @return
	 */
	public Integer deleteWarning(Long wid) {
		// TODO Auto-generated method stub
		return warningMapper.deleteWarning(wid);
	}
	
	/**
	 * 批量删除预警管理
	 * @param idArr
	 * @return
	 */
	@Transactional(rollbackFor={Exception.class})
	public Integer deleteWarnings(String [] idArr) {
		// TODO Auto-generated method stub
		int isSuccess = 0;
		try {
			for (int i = 0; i < idArr.length; i++) {
				isSuccess = warningMapper.deleteWarning(Long.parseLong(idArr[i]));
			}
		} catch (Exception e) {
			e.printStackTrace();     
	        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
	        isSuccess = 0;
		}
		return isSuccess;
	}

}
